////////smoke_sensor//////////
/*-------------------------------------------------------------------------------------------------------
get tcp,len=159:{"head":{"gatewayId":"gw_1C3283005078","msgId":29,"timeStamp":0,"cmd":"readAttr"},"data":{"privAddr":20,"channel":1,"nodeType":1,"mask":"01","classMask":"11"}}

read_attr_num=2, uploadNum=2, totalFrame=1
{"head":{"gatewayId":"gw_1C3283005078","replaceId":"","msgId":29,"timeStamp":1736496900,"response":"readAttr"},
"data":{"nodeType":1,"channel":1,"privAddr":20,"mac":"FFFFFFFFFFFF","name":"smoke_1_6","pid":"4007","totalFrame":1,"currFrame":1
,"totalAttr":2,"itemCnt":2},"attrLst":[
{"name":"almStatusSmoke","lable":"状态","class":25,"dpid":16,"val":0},
{"name":"alarmEn","lable":"烟雾报警使能","class":20,"dpid":1568,"val":0}]}





{"head":{"gatewayId":"gw_1C3283005078","msgId":35,"timeStamp":0,"cmd":"readAttr"},"data":{"privAddr":20,"channel":1,"nodeType":1}}
Tcp_ch1_TxData copy done
12:38:30- ETH_1 local_ktj_js Rx: len=503
{"head":{"gatewayId":"gw_1C3283005078","replaceId":"","msgId":35,"timeStamp":1736570310,"response":"readAttr"},
"data":{"nodeType":1,"channel":1,"privAddr":20,"mac":"FFFFFFFFFFFF","name":"smoke_1_6","pid":"4007","totalFrame":1,"currFrame":1,"totalAttr":3,"itemCnt":3},
"attrLst":[
{"name":"almStatusSmoke","lable":"状态","class":25,"dpid":16,"val":0},
{"name":"almDelay","lable":"报警延时","class":25,"dpid":17,"val":0},
{"name":"alarmEn","lable":"烟雾报警使能","class":20,"dpid":1568,"val":0}]}

-------------------------------------------------------------------------------------------------------*/



//#include "dev_smoke.h"


#ifndef __DEV_SMOKE_H__
#define __DEV_SMOKE_H__

#include "dev_module.h"
#include "iot_message.pb.h"
#include <stdint.h>
#include "iot_node.h"




#define  smoke_max_scale_0_01mm   (100000U)    //1000mm===1000x100 (0.01mm)
#define  smoke_max_dev_addr        (245U)      // 烟雾设备地址	R/W	否	配置参数	uint8_t	0~255
#define  smoke_max_channel          (31U)      // 烟雾设备通道编号	R/W	否	配置参数	uint8_t	0~31




/*-----------------------------------------------------------------------------------------------							
0x0801	软件版本	RO	否	软件版本	string	最大32字节			
0x0802	硬件版本	RO	否	硬件版本	string	最大32字节			
0x0803	产品型号	RO	否	产品型号	string	最大32字节			
0x0804	生产信息	RO	否	生产信息	string	最大32字节			生产日期，生产批次等信息
0x0805	厂家信息	RO	否		string	最大32字节			生产商名称信息

-----------------------------------------------------------------------------------------*/

/////-----设备类型----
//#define   DEV_SMOKE_TYPE     (0xD006)     //烟雾传感器（D006H） 



////以下枚举的取值 需要结合 数组 smoke_iot_id_table[smoke_index_end]的下标进行关联的定义---同步更新----
typedef enum{

    smoke_index_run_data_begin      = 0,    // 设备运行参数
    smoke_index_run_data_end        = 1,  
    smoke_index_config_data_begin   = 1,    // 设备配置参数-------------超过 8个时需要分帧处理
    smoke_index_factory_info_begin  = 5,   // 设备出厂信息
    smoke_index_end = 10,

} smoke_attr_index_e;







#pragma pack(1)

//0x0500	烟雾报警信息 "0=正常，1=告警
typedef union{
    struct{
        uint32_t en :  1;      // 报警使能
        uint32_t res1:31;
    }bit;
    uint32_t value;
} smoke_alarm_u;


//烟雾传感器（D006H）的数据
///---------RO 数据--------//
typedef struct{

    smoke_alarm_u  alarm;   //0x0500	烟雾报警信息"0=正常，1=告警
                             //bit0：烟雾报警
} smoke_data_t;

///---------R/W	配置参数--------//
typedef struct{

    uint8_t   addr;              //烟雾设备地址  0~255			
    uint8_t   channel;           //0x0602	烟雾设备通道编号	0~31	

    smoke_alarm_u   alarm_enable;       //0x0620 烟雾报警使能 "0=不启用，1=启用
    uint32_t        alarm_delay_sec;    //0x0621	报警延时时间	R/W	否	配置参数	uint32_t	0~65535	sec


    // uint32_t  under_level_th;    //烟雾过低阈值  0.01mm
    // uint32_t  over_level_th;     //烟雾过高阈值  0.01mm

    // uint32_t  monitor_sec_th;    //监测时间		sec
    // uint32_t  monitor_level_th;  //烟雾异常值	0.01mm


} smoke_config_t;




//---配置节点信息----------


typedef union
{
	struct{	
		
	  uint16_t online                  :1;	  //节点在线标志-----1:在线，0:离线，

	  uint16_t res                     :15;  
		
	}bit;
	
  uint16_t all;

} smoke_node_flags_u;




/*  ----------------------- --------------------------
typedef struct{

    char soft_ver[33];
    char hard_ver[33];
    char product_model[33];     //0x0803	产品型号

    char production_info[33];        //生产信息----生产日期，生产批次等信息
    char manufacturer[33];      //0x0805	厂家信息- 最大32字节 生产商名称信息----manufacturer--factory--producer---

} smoke_info_t;

----------------------- --------------------------*/

// typedef enum{

//     index_1,    //
//     index_max,

// } smoke_index_e;


//#define   SMOKE_NODE_NUM_MAX    (255U)  
#define   SMOKE_NODE_NUM_MAX    (NODE_NUM_MAX)     ///与配置节点总数相关-----



typedef struct{
    smoke_data_t      data;
    smoke_config_t    config;
    dev_attr_com_info_t  info;
    smoke_node_flags_u  flags;
 //   char   dev_name_str[32];   
} smoke_attr_t;


#pragma pack()

extern const  uint16_t  smoke_iot_id_table[smoke_index_end];

/**
 * @brief 
 * 
 */
void smoke_param_init(void);

uint8_t smoke_add_obj(uint8_t idx,uint8_t channel,uint8_t addr);


/**
 * @brief 
 * 
 * @param in idx 
 * @return smoke_attr_t ==NULL 查询出错,   !NULL 查询ok
 */
smoke_attr_t*  smoke_get_obj(uint8_t idx) ;  //smoke_attr_get


/**
 * @brief smoke_set_obj() 赋值节点数据
 * 
 * @param in idx
 * @param in p_attr
 * @return 0=失败，1=成功 
 */
uint8_t  smoke_set_obj(uint8_t idx,smoke_attr_t* p_attr )  ;



  //  smoke_index_run_data_begin      = 0,    // 设备运行参数
  //  smoke_index_config_data_begin   = 3,    // 设备配置参数
/**
 * @brief 根据下标，获取iot_id 的编号
 * 
 * @param idx 
 */
uint16_t  smoke_get_iot_id(uint8_t idx);


/**
 * @brief 
 * 
 * @param attr_id 
 * @param attr_out 
 */
void smoke_get_attr(uint8_t idx,uint16_t attr_id, IotModel* attr_out);


/**
 * @brief 
 * 
 * @param attr_in 
 * @return uint8_t 
 */
uint8_t smoke_set_attr(uint8_t idx,IotModel* attr_in);


void smoke_test_tick_min(uint8_t idx);

////刷新节点运行数据
void smoke_update_tick_min(uint8_t idx,int8_t temper ,uint32_t smoke );

void smoke_obj_update(uint8_t idx,smoke_attr_t* pliq_in  );




#endif //------__DEV_SMOKE_H__




















